package main

import (
	"demo/models"
	_ "demo/routers"
	"github.com/beego/beego/v2/client/orm"
	beego "github.com/beego/beego/v2/server/web"
)

func init() {
	val, _ := beego.AppConfig.String("defaultdb")
	ormdebug, _ := beego.AppConfig.Bool("ormdebug")
	driverName, _ := beego.AppConfig.String("db_driver_name")
	db_SetMaxIdleConns, _ := beego.AppConfig.Int("db_SetMaxIdleConns")
	db_SetMaxOpenConns, _ := beego.AppConfig.Int("db_SetMaxOpenConns")

	//orm.DefaultTimeLoc = time.Local
	orm.RegisterDriver(driverName, orm.DRMySQL)
	orm.RegisterDataBase("default", driverName, val)
	//根据数据库的别名，设置数据库的最大空闲连接
	orm.SetMaxIdleConns("default", db_SetMaxIdleConns)
	//根据数据库的别名，设置数据库的最大数据库连接
	orm.SetMaxOpenConns("default", db_SetMaxOpenConns)
	orm.Debug = ormdebug
}

func main() {
	//swagger接口文档访问路由
	if beego.BConfig.RunMode == "dev" {
		beego.BConfig.WebConfig.DirectoryIndex = true
		beego.BConfig.WebConfig.StaticDir["/swagger"] = "swagger"
	}

	//Admin 管理后台,开启后台进程监控，请求统计等
	beego.BConfig.Listen.EnableAdmin = true
	beego.BConfig.Listen.AdminAddr = "localhost"
	beego.BConfig.Listen.AdminPort = 8088

	beego.Run()

	//关闭gorm连接
	defer models.GormDB.Clauses()
}
